<?php

namespace App\Models\Activity;

use App\Models\BaseModel;
use App\Models\Shop\ShopModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ActivityShopRelModel extends BaseModel
{
    use HasFactory, KfSoftDeletes, KfUid;

    protected $table = "activity_shop_rel";

    /**
     * @return HasOne
     */
    public function shopDetailRel(): HasOne
    {
        return $this->hasOne(ShopModel::class, "id", "shopId");
    }

    /**
     * @return HasOne
     */
    public function activityRel(): HasOne
    {
        return $this->hasOne(ActivityModel::class, "id", "activityId");
    }

    /**
     * 活动 - 可参与门店关联
     * @param int $activityId
     * @param int $shopId
     * @return bool
     */
    public static function getActivityShopRel(int $activityId, int $shopId): bool
    {
        $info = self::query()
            ->where('activityId', $activityId)
            ->where('shopId', $shopId)
            ->first();

        return (bool)$info;
    }
}
